import type { PageType } from "@/api/type";
import request from "@/util/request";
import type {SocPostItemVO, SocPost, SocPostCreateDTO, SocPostTags,SocPostCategory,SocPostReplies ,SocPostInfoVO} from "./type";

enum API {
    POSTS_PAGE_URL = "/social/posts/page",
    POSTS_URL = "/social/posts",
    POSTS_REPLIES_URL_PAGE = "/social/posts/replies/page",
    POST_TAGE_BASE="/social/post/tag",
    POST_TAG_PAGE="/social/post/tag/page",
    POST_CATEGORY_PAGE="/social/post/category/page",
    POST_CATEGORY_BASE="/social/post/category",
}

export function reqGetPostPage(params: object) {
    return request<PageType<SocPostItemVO>>({
        url: API.POSTS_PAGE_URL,
        method: 'get',
        params
    })
}
/**
 * 创建帖子的请求
 * @param data
 * @returns
 */
export function reqCreatePost(data: SocPostCreateDTO) {
    return request<PageType<SocPost>>({
        url: API.POSTS_URL,
        method: 'post',
        data
    })
}
export function reqUpdatePost(data: SocPost) {
    return request<PageType<SocPost>>({
        url: API.POSTS_URL,
        method: 'put',
        data
    })
}
export function reqDeletePostById(postId: string) {
    return request<PageType<SocPost>>({
        url: API.POSTS_URL + "/" + postId,
        method: 'delete',
    })
}
export function reqGetPostById(postId: string) {
    return request<SocPostItemVO>({
        url: API.POSTS_URL + "/" + postId,
        method: 'get',
    })
}
export function reqGetPostRepliesPage(params: object) {
    return request<PageType<SocPostReplies>>({
        url: API.POSTS_REPLIES_URL_PAGE,
        method: 'get',
        params
    })
}
export function reqGetPostInfoVO(){
    return request<SocPostInfoVO>({
        url: API.POSTS_URL + "/info",
        method: 'get',
    })
}
export function reqGetPostTagPage(query: object){
    return request<PageType<SocPostTags>>({
        url: API.POST_TAG_PAGE,
        method: 'get',
        params:query
    })
}
export function reqGetPostTagById(tagId: string){
    return request<SocPostTags>({
        url: API.POST_TAGE_BASE + "/" + tagId,
        method: 'get',
    })
}
export function reqDeletePostTagById(tagId: string){
    return request<SocPostTags>({
        url: API.POST_TAGE_BASE + "/" + tagId,
        method: 'delete',
    })
}
export function reqUpdatePostTag(data: SocPostTags){
    return request<SocPostTags>({
        url: API.POST_TAGE_BASE,
        method: 'put',
        data
    })
}
export function reqAddPostTag(data: SocPostTags){
    return request<SocPostTags>({
        url: API.POST_TAGE_BASE,
        method: 'post',
        data
    })
}
export function reqGetPostCategoryPage(query){
    return request<SocPostCategory[]>({
        url: API.POST_CATEGORY_PAGE,
        method: 'get',
        params:query
    })
}
export function reqAddPostCategory(data: SocPostCategory){
    return request<SocPostCategory>({
        url: API.POST_CATEGORY_BASE,
        method: 'post',
        data
    })
}
export function reqDeletePostCategoryById(categoryId: string){
    return request<SocPostCategory>({
        url: API.POST_CATEGORY_BASE + "/" + categoryId,
        method: 'delete',
    })
}
export function reqUpdatePostCategory(data: SocPostCategory){
    return request<SocPostCategory>({
        url: API.POST_CATEGORY_BASE,
        method: 'put',
        data
    })
}
export function reqGetPostCategoryById(categoryId: string){
    return request<SocPostCategory>({
        url: API.POST_CATEGORY_BASE + "/" + categoryId,
        method: 'get',
    })
}
export function reqGetCategoryTagCount(categoryId: string){
    return request<number>({
        url: API.POST_CATEGORY_BASE + "/" + categoryId + "/tag/count",
        method: 'get',
    })
}

/**
 * 获取分类的父级分类（排除第三季分类）
 */
export function reqGetCategooryParentList(){
    return request<SocPostCategory[]>({
        url: API.POST_CATEGORY_BASE + "/parent/tree/list",
        method: 'get',
    })
}

//用户相关
export function reqGetPostUserPage(query){
    return request<PageType<SocPostItemVO>>({
        url: API.POSTS_URL + "/user/page",
        method: 'get',
        params:query
    })
}
